﻿using MediatR;
using Medical.Api.Read.Application.Command.Wms.WmsStoresCommand;
using Medical.Api.Read.Service.WmsService;
using System.Threading;
using System.Threading.Tasks;

namespace Medical.Api.Read.Application.Handler.Wms.WmsStoresHandler
{
    /// <summary>
    /// 物品详情查询处理器，根据物品id和类型获取详情
    /// </summary>
    public class GetMaterialByIdHandler : IRequestHandler<GetMaterialByIdCommand, MaterialDetailDto>
    {
        /// <summary>
        /// WMS服务
        /// </summary>
        private readonly IWmsService _service;
        /// <summary>
        /// 构造函数，注入WMS服务
        /// </summary>
        public GetMaterialByIdHandler(IWmsService service)
        {
            _service = service;
        }
        /// <summary>
        /// 查询物品详情（器械/器械包）
        /// </summary>
        /// <param name="request">物品id和类型命令</param>
        /// <param name="cancellationToken"></param>
        /// <returns>物品详情</returns>
        public async Task<MaterialDetailDto> Handle(GetMaterialByIdCommand request, CancellationToken cancellationToken)
        {
            return await _service.GetMaterialByIdAsync(request.Id, request.MaterialType);
        }
    }
}
